<form id="addOrUpdateForm" lay-filter="addOrUpdateForm" class="layui-form model-form">

    <input name="id" type="hidden"/>
    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">培训单位</label>
        <div class="layui-input-block">
            <input name="studyTitle" class="layui-input" placeholder="请输入培训单位" lay-verType="tips" lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">人员</label>
        <div class="layui-input-block">
            <div id="examinee"></div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">内容</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入学习经历内容" class="layui-textarea" name="studyContent"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">开始时间</label>
        <div class="layui-input-block">
            <input type="text" name="studyTime" id="studyTimeId" placeholder="请选择开始时间" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">结束时间</label>
        <div class="layui-input-block">
            <input type="text" name="endtime" id="endtimeId" placeholder="请选择结束时间" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">培训时长</label>
        <div class="layui-input-block">
            <input name="studyDuration" type="number" class="layui-input" placeholder="请输入学习经历时长" lay-verType="tips" lay-verify="required" required/>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">备注</label>
        <div class="layui-input-block">
            <input name="remark" class="layui-input" placeholder="请输入备注" lay-verType="tips"/>
        </div>
    </div>

    <div class="layui-form-item text-right">
        <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        <button class="layui-btn" lay-filter="formSubmitBtn" lay-submit>保存</button>
    </div>
</form>

<script>
    layui.use(['layer', 'form', 'admin', 'xnUtil', 'xmSelect', 'laydate'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var admin = layui.admin;
        var xnUtil = layui.xnUtil;
        var xmSelect = layui.xmSelect;
        var laydate = layui.laydate;

        laydate.render({
            elem: '#studyTimeId'
        });
        laydate.render({
            elem: '#endtimeId'
        });


        var editData = admin.getLayerData('#addOrUpdateForm').data;
        if(editData !== null && editData !== undefined) {
            form.val('addOrUpdateForm', editData);
        }

        /**
         * 表单提交事件
         */
        form.on('submit(formSubmitBtn)', function (data) {
            layer.load(2);
            data.field.name = $("#examinee")[0].innerText;
            var url = editData ? getProjectUrl() + 'sysUserStudyExperience/edit' : getProjectUrl() + 'sysUserStudyExperience/add';
            admin.req(url, JSON.stringify(data.field), function(res){
                layer.msg(res.message, {icon: 1, time: 1000}, function () {
                    admin.putLayerData('formOk', true, '#addOrUpdateForm');
                    admin.closeDialog('#addOrUpdateForm');
                });
            }, 'post');
            return false;
        });

        // 渲染远程数据下拉
        var grantRoleRenderIns = {};
        admin.req(getProjectUrl() + 'sysRole/dropUserDown', function (res) {
            debugger;
            grantRoleRenderIns = xmSelect.render({
                el: '#examinee',
                name: 'userId',
                data: res.data,
                toolbar: {
                    show: true
                },
                filterable: true,
                paging: true,
                pageSize: 10,
                radio: true,
                prop: {
                    name: 'name',
                    value: 'id'
                },
                model: {
                    label: {
                        type: 'block',
                        block: {
                            //最大显示数量, 0:不限制
                            showCount: 8
                        }
                    }
                },
                tips: '请选择用户'
            });
        }, {async: false});

        if (editData !== null && editData !== undefined) {
            debugger;
            var arrs = [];
            arrs.push(editData.userId);
            grantRoleRenderIns.setValue(arrs);
        }
    });
</script>
</body>
</html>
